import MySQLdb
import pprint
# connection = MySQLdb.connect(host='192.168.230.128',
#                      user='songqin',
#                      passwd='songqin',
#                      db="plesson",
#                      charset='utf8')
# c = connection.cursor()
# c.execute('''SELECT * FROM sq_course  ''' )
# # c.execute("INSERT INTO sq_course (name,`desc`,display_idx)VALUES('python','python课',3)")
# # c.execute("DELETE FROM sq_course where name = 'c++'")
# # c.execute("UPDATE sq_course set name='python',`desc`='python基础2'where id =1")
# connection.commit()
#
# #获取数据库数据行数
# numrows = c.rowcount
# print(numrows)
#
# #返回元组，每个元素代表一个字段
# for one in range(numrows):
#     row=c.fetchone()
#     print(row)
#
# #指定获取数据条数
# # data = c.fetchmany(3)
# # pprint.pprint(data)
#
# # #获取所有数据库数据
# # data1 = c.fetchall()
# # pprint.pprint(data1)

import MySQLdb



# import MySQLdb
# import pprint
# # 打开数据库连接
# conn = MySQLdb.connect(host='193.112.244.133',
#                        port=8003,
#                        user='root',
#                        passwd='Pagoda@123!',
#                        db='v2_pagoda_customer2',
#                        charset='utf8'
#                        )
# # 使用 cursor() 方法创建一个游标对象 cursor
# cursor = conn.cursor()
#
# # 使用 execute()  方法执行 SQL 查询
# # cursor.execute("use v2_pagoda_customer2;") #在MySQLdb.content添加了db，就不需要cursor.execute来进行选择数据库
# cursor.execute('select * from chains_order')
# numrows=cursor.rowcount#获取表内容的行数
# # print(cursor.rowcount)
#
# #返回元组，每个元素代表一个字段
# for one in range(numrows):
#     row=cursor.fetchone()
#     print(row)

#获取总条数
# dataall=cursor.fetchall()
# print(dataall)

# # 指定获取数据条数
# data = cursor.fetchmany(4)
# print(data)
#
# #获取一条
# dataone=cursor.fetchone()
# print(dataone)
#


import pymysql
conn=pymysql.connect(host='10.8.62.13',
                       port=8003,
                       user='root',
                       passwd='Pagoda@123!',
                       db='v2_pagoda_customer2',
                       charset='utf8')
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = conn.cursor()

# 使用 execute()  方法执行 SQL 查询
# cursor.execute("use v2_pagoda_customer2;") #在MySQLdb.content添加了db，就不需要cursor.execute来进行选择数据库
cursor.execute("select * from chains_order")
# cursor.execute("insert into chains_order(id,customerID,number,orderAmount) values('4','1000857389','3008720101915080924961','3210')")
# conn.commit()#提交数据
#
numrows=cursor.rowcount#获取表chains_order内容的行数
# print(cursor.rowcount)

# 返回元组，每个元素代表一个字段
for one in range(numrows):
    row=cursor.fetchone()
    print(row)

# 获取一行数据
# dataone=cursor.fetchone()
# print(dataone)
# print(dataone[0],dataone[1])

#获取多行数据
# datamany=cursor.fetchmany(2)
# print(datamany)

# 获取全部数据
# dataall=cursor.fetchall()
# print(dataall)

# cursor.close()#关闭数据库的连接
